// order.js
Page({
  data: {
    categories: ['热销', '主食', '小吃', '饮品'],
    currentCategory: '热销',
    products: [
      { id: 1, name: '宫保鸡丁', price: 28, category: '热销' },
      { id: 2, name: '米饭', price: 2, category: '主食' },
      { id: 3, name: '春卷', price: 15, category: '小吃' },
      { id: 4, name: '可乐', price: 5, category: '饮品' }
    ],
    selectedProduct: null
  },
  changeCategory: function(e) {
    this.setData({
      currentCategory: e.currentTarget.dataset.category
    })
  },
  selectProduct: function(e) {
    const productId = e.currentTarget.dataset.id
    const product = this.data.products.find(p => p.id === productId)
    this.setData({
      selectedProduct: product
    })
  },
  addToCart: function() {
    const app = getApp()
    app.globalData.cartItems.push(this.data.selectedProduct)
    wx.showToast({
      title: '已添加到购物车',
      icon: 'success'
    })
  },
  goToCart: function() {
    wx.switchTab({
      url: '/pages/cart/cart'
    })
  }
})
